package datasv.collegeQuery_datasv;

import java.util.Date;

import data.datafactory.DatabaseOperator;
import po.StudentPO;
import resultmessage.CollegeQueryRM;

public class AddStudent {
	public static void main(String[] args) {
		System.out.println(new AddStudent().addStudent("001", new StudentPO("001131002","Test.T",new Date(1993,03,18),"testT","TestT", 2012), "001131002"));
		System.out.println("datasv addStudent successfully");
	}
	public CollegeQueryRM addStudent(String collegeID, StudentPO po,
			String studentID) {
		return addInSql(collegeID, po, studentID);
	}

	private CollegeQueryRM addInSql(String collegeID, StudentPO po,
			String studentID) {
		DatabaseOperator op = new DatabaseOperator("college" + collegeID);
		if (!op.ifDatabaseExist()) {
			return CollegeQueryRM.COLLEGE_NOT_EXIT;
		}
		if (op.ifIDExist("student_list", po.getStudentID())) {
			return CollegeQueryRM.STUDENT_EXIST;
		}
		int num = op.numOfColumn("student_list");
		String[][] m = new String[num][num];
		String[] n = op.getColumnName("student_list");
		for (int i = 0; i < num; i++) {
			m[i][0] = n[i];
			//System.out.println("column Name : " + n[i]);
		}
		m[0][1] = po.getStudentID();// ID
		m[1][1] = po.getName();// name
		m[2][1] = Integer.toString(po.getBirthday().getYear())+"/"+Integer.toString(po.getBirthday().getMonth())+"/"+Integer.toString(po.getBirthday().getDate());// birthday
		m[3][1] = po.getCollegeID();// college id
		m[4][1] = po.getDepartment();// department
		m[5][1] = Integer.toString(po.getEduStartYear());// educate start year
		if (!op.addOneRow(m, "student_list")) {
			return CollegeQueryRM.STUDENT_EXIST;
		}
		return CollegeQueryRM.SUCCESS;

	}
}
